<template>
  <div>
    <el-dialog
      :title="this.$t('ExpressOrderManagementLang.issueAccounts')"
      :visible.sync="Visible"
      width="100%"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <div class="midContant clearfix">
        <div class="dialogBox top">
          <div class="dialogBoxTitle">{{$t('ExpressDeliveryManagementLang.Waybill_info')}}</div>
          <div class="dialogBoxItem">
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Waybill_date')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.waybill_day_date"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.currency')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.currency_type_name"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Promise_days')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.duration"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Type_goods')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.cargo_type"
                ></el-input>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.IsBrand')}}:
              </div>
              <div class="contant">
                <el-select
                  disabled
                  v-model="data.is_brand"
                  :placeholder="$t('common.select_plactholder')"
                >
                  <el-option
                    v-for="item in options_IsBrand"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.type_shipping')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.trans_type"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Origin')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.start_local_name"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.destination')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.target_local_name"
                ></el-input>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Shipper')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.username"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.sale')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.order_sale_uid_name"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.sender')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.pickup_name"
                ></el-input>
              </div>
            </div>
            <div class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Sender_phone_number')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.pickup_tel"
                ></el-input>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Number_packages')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.package_num"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.weights')}}kg:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.gross_weight"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressOrderManagementLang.Weight_measurement')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.weight"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.volumes')}}m³:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.volume"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressOrderManagementLang.Volume_measurement')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.cal_volume"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.number')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.quantity_num"
                ></el-input>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Ticket_number')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.ticket_num"
                ></el-input>
              </div>
            </div>
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Product_Name')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.goods_name"
                ></el-input>
              </div>
            </div>
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Billing_method')}}:
              </div>
              <div class="contant">
                <el-select
                  :disabled="!!data.out_bill_status"
                  ref="billInfo.price_category"
                  filterable
                  @blur="handleBlur('billInfo.price_category', $event)"
                  @change="handleChang('billInfo.price_category')"
                  v-model="data.billInfo.price_category"
                  :placeholder="$t('common.select_plactholder')"
                >
                  <el-option
                    v-for="item in options_Unit_price"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
            </div>
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status&&data.billInfo.price_category==3" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Bubble_weight_freight')}}:
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status||data.billInfo.price_category!=3"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.weight_calc_rule" 
                  @blur="handleBlur('billInfo.weight_calc_rule', $event)" 
                  @focus="handleFocus($event)" 
                  @change="()=>{this.setWeightFreight();this.getFreightPrice();}"
                  :min="1" 
                  :precision="0"
                  v-model="data.billInfo.weight_calc_rule">
                </el-input-number>
              </div>
            </div>
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Weight_measurement_freight')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.billInfo.weight"
                ></el-input>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Unit_Price')}}({{current_currency_matches}}/{{current_billing_method_matches}}):
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.unit_price" 
                  @blur="handleBlur('billInfo.unit_price', $event)" 
                  @focus="handleFocus($event)" 
                  @change="setPrice"
                  :min="0" 
                  :precision="2"
                  v-model="data.billInfo.unit_price">
                </el-input-number>
              </div>
            </div>
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status" class="RequiredRowTip">*</div>
                {{$t('ExpressOrderManagementLang.Whole_price')}}({{current_currency_matches}}):
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.whole_price" 
                  @blur="handleBlur('billInfo.whole_price', $event)" 
                  @focus="handleFocus($event)" 
                  @change="setPrice"
                  :min="0" 
                  :precision="2"
                  v-model="data.billInfo.whole_price">
                </el-input-number>
              </div>
            </div>
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressOrderManagementLang.freight')}}({{current_currency_matches}}):
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.billInfo.trans_price"
                ></el-input>
              </div>
            </div>
            <div style="width: 19%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.discount')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.billInfo.discount"
                ></el-input>
              </div>
            </div>
            <div style="width:19%" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressOrderManagementLang.discount_Freight')}}({{current_currency_matches}}):
              </div>
              <div class="contant">
                <el-input-number
                  disabled
                  controls-position="right"
                  size="small" 
                  v-model="data.billInfo.discount_trans_price">
                </el-input-number>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.payment_method')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.pay_type_name"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Insurance_type')}}:
              </div>
              <div class="contant">
                <el-select
                  :disabled="!!data.out_bill_status"
                  ref="billInfo.is_insure"
                  filterable
                  @blur="handleBlur('billInfo.is_insure', $event)"
                  @change="handleChang('billInfo.is_insure')"
                  v-model="data.billInfo.is_insure"
                  :placeholder="$t('common.select_plactholder')"
                >
                  <el-option
                    v-for="item in options_insure"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status&&data.billInfo.is_insure!=0" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.yibao_billing_method')}}:
              </div>
              <div class="contant">
                <el-select
                  :disabled="!!data.out_bill_status||data.billInfo.is_insure==0"
                  ref="billInfo.premiums.type"
                  filterable
                  @blur="handleBlur('billInfo.premiums.type', $event)"
                  @change="handleChang('billInfo.premiums.type')"
                  v-model="data.billInfo.premiums.type"
                  :placeholder="$t('common.select_plactholder')"
                >
                  <el-option
                    v-for="item in options_protection"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status&&data.billInfo.premiums.type==3" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Bubble_weight_insurance')}}:
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status||data.billInfo.premiums.type!=3"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.premiums.bw_rate" 
                  @blur="handleBlur('billInfo.premiums.bw_rate', $event)" 
                  @focus="handleFocus($event)" 
                  @change="()=>{this.setWeightInsurance();this.setInsurePrice();}"
                  :min="1" 
                  :precision="0"
                  v-model="data.billInfo.premiums.bw_rate">
                </el-input-number>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Weight_measurement_insurance')}}:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.billInfo.premiums.insure_weight"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status&&data.billInfo.is_insure!=0" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Unit_price_voluntary')}}({{current_currency_matches}}/{{current_charging_protect_price_type_matches}}):
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status||data.billInfo.is_insure==0"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.insure_unit_price" 
                  @blur="handleBlur('billInfo.insure_unit_price', $event)" 
                  @focus="handleFocus($event)" 
                  @change="setInsurePrice"
                  :min="0" 
                  :precision="2"
                  v-model="data.billInfo.insure_unit_price">
                </el-input-number>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status&&data.billInfo.is_insure==0" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Insured_price')}}:
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status||data.billInfo.is_insure!=0"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.insure_price" 
                  @blur="handleBlur('billInfo.insure_price', $event)" 
                  @focus="handleFocus($event)" 
                  @change="match_premium_rate"
                  :min="premium_min" 
                  :precision="2"
                  :max="premium_max"
                  v-model="data.billInfo.insure_price">
                </el-input-number>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                <div v-if="!data.out_bill_status" class="RequiredRowTip">*</div>
                {{$t('ExpressDeliveryManagementLang.Guarantee_rate')}}:
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.premium_rate" 
                  @blur="handleBlur('billInfo.premium_rate', $event)" 
                  @focus="handleFocus($event)" 
                  @change="setInsureCost"
                  :min="0" 
                  :precision="2"
                  v-model="data.billInfo.premium_rate">
                </el-input-number>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.premium')}}({{current_currency_matches}}):
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.billInfo.insure_cost"
                ></el-input>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.service_charge')}}￥:
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.billInfo.service_price"
                ></el-input>
                <div style="margin-left:5px;white-space:nowrap;color:#62afff;cursor:pointer;" @click="details">{{$t('common.details')}}</div>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.reduction')}}({{current_currency_matches}}):
              </div>
              <div class="contant">
                <el-input-number
                  :disabled="!!data.out_bill_status"
                  controls-position="right"
                  size="small" 
                  ref="billInfo.reduce" 
                  @blur="handleBlur('billInfo.reduce', $event)" 
                  @focus="handleFocus($event)" 
                  @change="setTotalPrice"
                  :min="0" 
                  :precision="2"
                  v-model="data.billInfo.reduce">
                </el-input-number>
              </div>
            </div>
            <div style="width: 15%;" class="dialogBoxItemRow">
              <div class="title">
                {{$t('ExpressDeliveryManagementLang.Total_amount')}}({{current_currency_matches}}):
              </div>
              <div class="contant">
                <el-input
                  disabled
                  v-model="data.billInfo.discount_total_price"
                ></el-input>
              </div>
            </div>
          </div>
        </div>
        <div class="dialogBox top">
          <div class="dialogBoxTitle">{{$t('ExpressOrderManagementLang.Product_information')}}</div>
          <MyTable
          :tableColumn="tableColumn_goods"
          :tableData="tableData_goods"
          :isOrder="false"
          >
            <template v-slot:content="scope">
              <span>{{ scope.row[scope.config.prop] }}</span>
            </template>
          </MyTable>
        </div>
        <div class="dialogBox top">
          <div class="dialogBoxTitle">{{$t('ExpressOrderManagementLang.Package_information')}}</div>
          <MyTable
            :tableColumn="tableColumn_packages"
            :tableData="tableData_packages"
            :isOrder="false"
          >
            <template v-slot:content="scope">
              <span>{{ scope.row[scope.config.prop] }}</span>
            </template>
          </MyTable>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirm" size="small"
          >{{$t('common.confirm')}}</el-button
        >
        <el-button  @click="cancel" size="small">{{$t('common.cancel')}}</el-button>
      </span>
      
    </el-dialog>
    <ServiceFee
      @success="detailsSuccess"
      ref="serviceFee"
    ></ServiceFee>
  </div>
</template>

<script>
import { debounce } from '@/utils/func.js'
import ServiceFee from "../ExpressDeliveryManagenment/ExpressDeliveryOrderManagement_issueAccounts_ServiceFee";
export default {
  components: {ServiceFee},
  props: {
    // 接收绑定参数
    midHight: [Number,String],
  },
  data() {
    return {
      Visible: false,
      order_sn:'',
      lid:'',
      data:{
        billInfo:{
          premiums:{}
        },
      },
      options_IsBrand:[],
      options_Unit_price: [],
      options_insure: [],
      options_protection:[],
      current_currency_matches:'$',
      current_billing_method_matches:'kg',
      current_charging_protect_price_type_matches:'kg',
      premium_min:0,//保险费最小值
      premium_max:0,//保险费最大值
      tableColumn_goods: [
        {
          label: "",
          prop: "table_code",
          width:40,
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Product_Name'),
          prop: "goods_name",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.commodity_value'),
          prop: "goods_price",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Quantity_goods'),
          prop: "goods_num",
          width: 120,
        },
        
      ],
      tableData_goods: [],
      tableColumn_packages: [
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.Number_packages'),
          prop: "package_num",
          width: 80,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.package_Number'),
          prop: "package_number",
          width: 80,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.weight'),
          prop: "gross_weight",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.long'),
          prop: "length",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.wide'),
          prop: "width",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.high'),
          prop: "height",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.volume'),
          prop: "volume",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.density'),
          prop: "density",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.goods_name'),
          prop: "goods_name",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.quantity_num'),
          prop: "quantity_num",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.model_num'),
          prop: "style_num",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.packing_method'),
          prop: "packing_method_name",
          width: 120,
        },
        {
          checked: true,
          label: this.$t('ExpressDeliveryManagementLang.remarks'),
          prop: "remark",
          width: 120,
        },
      ],
      tableData_packages: [],
      confirmTrue:true,//确定按钮保护
      start_weight:1,
      renew_weight:1,
      premiumRangeList:[],
    };
  },
  created() {
    
  },
  mounted() {
  },
  deactivated(){
    
  },
  methods: {
   
    init(data) {
      this.order_sn=data.order_sn
      this.lid=data.lid
      this.Visible = true;
      this.getData();
      this.getOptions();
    },
    //获取下拉单数据
    getOptions(){
      this.$get("lineSysItems").then((res) => {
        this.options_IsBrand = res.data.is_brand;
        this.options_insure = res.data.line_type;
        this.options_protection = res.data.premium_type;
      });
      this.$get("freightSysItems").then((res) => {
        this.options_Unit_price = res.data.price_type;
      });
    },
    //获取单条
    getData() {
      this.$get("waybillBillInfo", { order_sn: this.order_sn,lid: this.lid}).then((res) => {
        this.data = res.data;
        this.tableData_goods=res.data.goods
        this.tableData_packages=res.data.packages
        this.start_weight=res.data.lines[0].start_weight
        this.renew_weight=res.data.lines[0].renew_weight
        this.start_volume=res.data.lines[0].start_volume
        this.renew_volume=res.data.lines[0].renew_volume
        this.premium_min=Number(res.data.lines[0].premium_min)
        this.premium_max=Number(res.data.lines[0].premium_max)
        if(!!this.data.out_bill_status){
          this.data.billInfo.premiums=JSON.parse(this.data.billInfo.premiums)
        }else{
          this.setWeightFreight()
          this.setWeightInsurance()
        }
        if(this.data.billInfo.price_category==2){
          this.current_billing_method_matches='m³'
        }else {
          this.current_billing_method_matches='kg'
        }
        if(this.data.billInfo.premiums.type==2){
          this.current_charging_protect_price_type_matches='m³'
        }else {
          this.current_charging_protect_price_type_matches='kg'
        }
        if(this.data.currency_type_name=="美元"){
          this.current_currency_matches='$'
        }else if(this.data.currency_type_name=="人民币"){
          this.current_currency_matches='￥'
        }else if(this.data.currency_type_name=="卢布"){
          this.current_currency_matches='₽'
        }
        this.$get("linePremiumRanges", { id: this.data.line_info.id }).then((res) => {
          this.premiumRangeList=res.data
        });
      });
    },
    details(){
      this.$refs.serviceFee.init(this.data.billInfo.serviceCharge,this.lid,this.tableData_packages,!!this.data.out_bill_status)
    },
    detailsSuccess(arr){
      this.data.billInfo.serviceCharge=arr
      this.data.billInfo.service_price=this.data.billInfo.serviceCharge.reduce(function(acc, obj) {
        return acc + Number(obj.price?obj.price:0);
      }, 0);
      this.setTotalPrice()
    },
    //输入框、下拉框失去焦点边框变色
    handleBlur(name, event) {
      let arr=name.split('.')
      let dataNum=this.data
      arr.forEach(item => {
        dataNum=dataNum[item]
      });
      if (!dataNum&&dataNum!==0) {
        event.target.style.border = "1px solid red";
      }
    },
    //输入框、下拉框获取焦点边框变色
    handleFocus(event) {
      event.target.style.border = "1px solid #E0E3E9";
    },
    //下拉框有值后边框变色
    handleChang(data) {
      let arr=data.split('.')
      if(data=='billInfo.price_category'){
        this.data.billInfo.weight_calc_rule=undefined
        this.$refs['billInfo.weight_calc_rule'].$el.childNodes[2].childNodes[1].style.border='1px solid #E0E3E9'
      }
      if(data=='billInfo.is_insure'){
        this.data.billInfo.insure_unit_price=''
        this.$refs['billInfo.insure_price'].$el.childNodes[2].childNodes[1].style.border='1px solid #E0E3E9'
      }
      if(data=='billInfo.premiums.type'){
        this.data.billInfo.premiums.bw_rate=undefined
        this.$refs['billInfo.premiums.bw_rate'].$el.childNodes[2].childNodes[1].style.border='1px solid #E0E3E9'
        this.setWeightInsurance()
      }
      let dataNum=this.data
      arr.forEach(item => {
        dataNum=dataNum[item]
      });
      if (dataNum.length==0) {
        this.$refs[data].$el.childNodes[1].childNodes[1].style.border = "1px solid red";
      }else{
        this.$refs[data].$el.childNodes[1].childNodes[1].style.border ="1px solid #E0E3E9 ";
      }
      // if(data=='item_id'){
      //   this.data.item_type=this.options_fields.filter(el=>{return el.id==this.data.item_id})[0].type
      // }
    },
     //获取运费单价
    getFreightPrice:debounce(function(row) {
      let params = new FormData();
      params.append("order_sn", this.order_sn);
      params.append("lid", this.lid);
      params.append("gross_weight", this.data.gross_weight);
      params.append("volume", this.data.volume);
      params.append("weight_calc_rule", this.data.billInfo.weight_calc_rule);
      this.$postForm("claFreight", params).then((res) => {
        this.data.billInfo.price_category=res.data.freight_category
        this.data.billInfo.unit_price=res.data.freight_price
        this.data.billInfo.whole_price=res.data.whole_price
        if(this.data.billInfo.price_category.length==0){
          this.data.billInfo.weight_calc_rule=undefined
          this.$refs['billInfo.weight_calc_rule'].$el.childNodes[2].childNodes[1].style.border='1px solid #E0E3E9'
        }
        this.setWeightFreight()
        this.setPrice()
      });
    },500),
    // 计算计重(运费)
    setWeightFreight(){
      if(this.data.billInfo.price_category==3){
        let Gross_weight=this.data.weight//通过毛重计算得出计重
        let Throwing_weight=this.$computing(Number(this.data.cal_volume*1000000)/Number(this.data.billInfo.weight_calc_rule||1),'ceil',1)//通过抛重计算得出计重
        if(Gross_weight>Throwing_weight){
          this.data.billInfo.weight=Gross_weight
        }else{
          this.data.billInfo.weight=Throwing_weight
        }
      }else if(this.data.billInfo.price_category!=2){        
        this.data.billInfo.weight=this.data.weight
      }
      if(this.data.billInfo.weight<=this.start_weight){
        this.data.billInfo.weight=this.start_weight
      }else{
        let multiple_weight=this.$computing(Number(this.data.billInfo.weight)/Number(this.renew_weight),'ceil',0)
        this.data.billInfo.weight=this.$computing(Number(multiple_weight)*Number(this.renew_weight),'fixed',1)
      }
    },
    //计算运费、折后运费
    setPrice(){
      if(this.data.billInfo.price_category==2){
        this.data.billInfo.trans_price=this.$computing(Number(this.data.cal_volume)*Number(this.data.billInfo.unit_price)+Number(this.data.billInfo.whole_price?this.data.billInfo.whole_price:0),'fixed',2)
      }else if(this.data.billInfo.price_category==1||this.data.billInfo.price_category==3){
        this.data.billInfo.trans_price=this.$computing(Number(this.data.billInfo.weight)*Number(this.data.billInfo.unit_price)+Number(this.data.billInfo.whole_price?this.data.billInfo.whole_price:0),'fixed',2)
      }
      this.data.billInfo.trans_price=Number(this.data.billInfo.trans_price)<0?0:this.data.billInfo.trans_price

      this.data.billInfo.discount_trans_price=this.$computing(this.data.billInfo.trans_price*(100-Number(this.data.billInfo.discount||0))/100,'fixed',2)
      this.setTotalPrice()
    },
    // 计算计重(保险)
    setWeightInsurance(){
      if(this.data.billInfo.premiums.type==3){
        let Gross_weight=this.data.weight//通过毛重计算得出计重
        let Throwing_weight=this.$computing(Number(this.data.cal_volume*1000000)/Number(this.data.billInfo.premiums.bw_rate||1),'ceil',1)//通过抛重计算得出计重
        if(Gross_weight>Throwing_weight){
          this.data.billInfo.premiums.insure_weight=Gross_weight
        }else{
          this.data.billInfo.premiums.insure_weight=Throwing_weight
        }
      }else if(this.data.billInfo.premiums.type!=2){        
        this.data.billInfo.premiums.insure_weight=this.data.weight
      }
      if(this.data.billInfo.premiums.insure_weight<=this.start_weight){
        this.data.billInfo.premiums.insure_weight=this.start_weight
      }else{
        let multiple_weight=this.$computing(Number(this.data.billInfo.premiums.insure_weight)/Number(this.renew_weight),'ceil',0)
        this.data.billInfo.premiums.insure_weight=this.$computing(Number(multiple_weight)*Number(this.renew_weight),'fixed',1)
      }
      this.match_premium_rate()
    },
    //计算保价
    setInsurePrice(){
      if(this.data.billInfo.premiums.type==2){
        this.data.billInfo.insure_price=this.$computing(Number(this.data.cal_volume)*Number(this.data.billInfo.insure_unit_price),'fixed',2)
      }else if(this.data.billInfo.premiums.type==1||this.data.billInfo.premiums.type==3){
        this.data.billInfo.insure_price=this.$computing(Number(this.data.billInfo.premiums.insure_weight)*Number(this.data.billInfo.insure_unit_price),'fixed',2)
      }
      if(this.data.billInfo.insure_price<this.premium_min){
        this.data.billInfo.insure_price=this.premium_min
      }else if(this.data.billInfo.insure_price>this.premium_max){
        this.data.billInfo.insure_price=this.premium_max
      }
      this.setInsureCost()
    },
    // 匹配对应保险费率
    match_premium_rate(){
      if(this.premiumRangeList.length>0){
        let arr=[]
        if(this.premiumRangeList[0].type==0){
          //区间类型是平均重量
          arr=this.premiumRangeList.filter(item=>{return this.data.insure_price/this.data.bill_calweight>=item.range_val_min&&this.data.insure_price/this.data.bill_calweight<=item.range_val_max})
        }else if(this.premiumRangeList[0].type==1){
          //区间类型是平均体积
          arr=this.premiumRangeList.filter(item=>{return this.data.insure_price/this.data.bill_cal_volume>=item.range_val_min&&this.data.insure_price/this.data.bill_cal_volume<=item.range_val_max})
        }else if(this.premiumRangeList[0].type==2){
          let density=0
          if(this.data.bill_cal_volume>0&&this.data.bill_calweight>0){
            density=this.$computing(Number(this.data.bill_calweight)/Number(this.data.bill_cal_volume),'fixed',2)
          }else{
            density=0
          }
          //区间类型是平均密度
          arr=this.premiumRangeList.filter(item=>{return this.data.insure_price/density>=item.range_val_min&&this.data.insure_price/density<=item.range_val_max})
        }else if(this.premiumRangeList[0].type==3){
          //区间类型是保值
          arr=this.premiumRangeList.filter(item=>{return this.data.insure_price>=item.range_val_min&&this.data.insure_price<=item.range_val_max})
        }
        if(arr.length>0){
          this.data.premium_rate=Number(arr[0].premium_rate)
        }else{
          this.data.premium_rate=0
        }
      }
    },
    //计算保险费
    setInsureCost(){
      this.data.billInfo.insure_cost=this.$computing(Number(this.data.billInfo.insure_price)*Number(this.data.billInfo.premium_rate)/100,'fixed',4)
      this.setTotalPrice()
    },
    //计算总金额
    setTotalPrice(){
      this.data.billInfo.discount_total_price=this.$computing(Number(this.data.billInfo.discount_trans_price)+Number(this.data.billInfo.insure_cost)+Number(this.data.billInfo.service_price)-Number(this.data.billInfo.reduce),'fixed',4)
    },
    // 提交修改
    confirm() {
      let type=true
      if (!this.data.billInfo.price_category&&this.data.billInfo.price_category!==0) {
        this.$refs['billInfo.price_category'].$el.childNodes[1].childNodes[1].style.border =
          "1px solid red";
        type = false;
      }
      if(this.data.billInfo.price_category==3&&!this.data.billInfo.weight_calc_rule){
        this.$refs['billInfo.weight_calc_rule'].$el.childNodes[2].childNodes[1].style.border='1px solid red'
        type=false
      }
      if(!this.data.billInfo.unit_price&&this.data.billInfo.unit_price!==0){
        this.$refs['billInfo.unit_price'].$el.childNodes[2].childNodes[1].style.border='1px solid red'
        type=false
      }
      if(!this.data.billInfo.whole_price&&this.data.billInfo.unit_price!==0){
        this.$refs['billInfo.whole_price'].$el.childNodes[2].childNodes[1].style.border='1px solid red'
        type=false
      }
      if (!this.data.billInfo.is_insure&&this.data.billInfo.is_insure!==0) {
        this.$refs['billInfo.is_insure'].$el.childNodes[1].childNodes[1].style.border =
          "1px solid red";
        type = false;
      }
      if(this.data.billInfo.is_insure!=0){
        if (!this.data.billInfo.premiums.type&&this.data.billInfo.premiums.type!==0) {
          this.$refs['billInfo.premiums.type'].$el.childNodes[1].childNodes[1].style.border =
            "1px solid red";
          type = false;
        }
        if(this.data.billInfo.premiums.type==3){
          if (!this.data.billInfo.premiums.bw_rate&&this.data.billInfo.premiums.bw_rate!==0) {
            this.$refs['billInfo.premiums.bw_rate'].$el.childNodes[2].childNodes[1].style.border =
              "1px solid red";
            type = false;
          }
        }
        if(!this.data.billInfo.insure_unit_price&&this.data.billInfo.insure_unit_price!==0){
          this.$refs['billInfo.insure_unit_price'].$el.childNodes[2].childNodes[1].style.border='1px solid red'
          type=false
        }
      }else{
        if(!this.data.billInfo.insure_price&&this.data.billInfo.insure_price!==0){
          this.$refs['billInfo.insure_price'].$el.childNodes[2].childNodes[1].style.border='1px solid red'
          type=false
        }
      }
      if(!this.data.billInfo.premium_rate&&this.data.billInfo.premium_rate!==0){
        this.$refs['billInfo.premium_rate'].$el.childNodes[2].childNodes[1].style.border='1px solid red'
        type=false
      }
      // 是否有空值必选项标识
      if (type && this.confirmTrue) {
        this.confirmTrue=false
        window.setTimeout(()=>{
          this.confirmTrue=true
        },1000)
        let params = new FormData();
        
        params.append("order_sn", this.order_sn);
        params.append("lid", this.lid);
        params.append("duration", this.data.duration);
        params.append("unit_price", this.data.billInfo.unit_price);
        params.append("price_category", this.data.billInfo.price_category);
        params.append("whole_price", this.data.billInfo.whole_price);
        params.append("weight", this.data.billInfo.weight);
        params.append("discount", this.data.billInfo.discount);
        params.append("weight_calc_rule", this.data.billInfo.weight_calc_rule);
        params.append("reduce", this.data.billInfo.reduce);
        params.append("insure_price", this.data.billInfo.insure_price);
        params.append("premium_rate", this.data.billInfo.premium_rate);
        params.append("bw_rate", this.data.billInfo.premiums.bw_rate);
        params.append("insure_weight", this.data.billInfo.premiums.insure_weight);
        params.append("is_insure", this.data.billInfo.is_insure);
        params.append("type", this.data.billInfo.premiums.type);
        params.append("insure_unit_price", this.data.billInfo.insure_unit_price);
        params.append("services", JSON.stringify(this.data.billInfo.serviceCharge));
        this.$postForm("saveWaybillBill", params).then((res) => {
          this.confirmTrue=true
          if(res.success){
            this.$message.success(res.msg);
            this.$emit("success");
            this.cancel()
          }
        });
      }
    },
    //取消修改
    cancel() {
      this.data={
        billInfo:{
          premiums:{}
        },
      }
      this.tableData_packages=[] 
      this.Visible = false;
    },
  },
};
</script>

<style scoped lang="less" >
  .midContant {
    border: 0;
    width: 100%;
  }
  .dialogBox .dialogBoxItem .dialogBoxItemRow {
    width: 24%;
  }
</style>